package com.abel.rabbitmq.mq;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Author: Abel.lin
 * Date: Created in 2018/5/31 16:31
 * Company: Abel.Studio
 * Copyright: Copyright (c) 2017
 * Description:
 */
@Component
public class Producer {
    private Logger log = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private AmqpTemplate amqpTemplate;

    public void normalSend(String context){
        log.info("{}:{}", RabbitConfig.NORMAL_QUEUE, context);
        amqpTemplate.convertAndSend(RabbitConfig.NORMAL_QUEUE, context);
    }

    public void fanoutSend(String context){
        log.info("{}:{}", RabbitConfig.FANOUT_EXCHANGE, context);
        amqpTemplate.convertAndSend(RabbitConfig.FANOUT_EXCHANGE, "", context);
    }

    public void routingSend(String routingKey, String context){
        log.info("{}:{}", RabbitConfig.ROUTING_EXCHANGE, context);
        amqpTemplate.convertAndSend(RabbitConfig.ROUTING_EXCHANGE, routingKey, context);
    }

    public void topicSend(String routingKey, String context){
        log.info("{}:{}", RabbitConfig.TOPIC_EXCHANGE, context);
        amqpTemplate.convertAndSend(RabbitConfig.TOPIC_EXCHANGE, routingKey, context);
    }
}
